package com.situ.mall.controller;

import com.situ.mall.pojo.entity.Cart;
import com.situ.mall.pojo.entity.Order;
import com.situ.mall.pojo.entity.OrderItem;
import com.situ.mall.pojo.entity.User;
import com.situ.mall.pojo.query.OrderQuery;
import com.situ.mall.pojo.vo.OrderVO;
import com.situ.mall.service.IOrderService;
import com.situ.mall.util.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @RequestMapping("/add")
    public Result add(Order order, HttpSession session) {
        User user = (User) session.getAttribute("user");
        order.setUserId(user.getId());
        orderService.add(order);
        return Result.ok("添加成功");
    }

    @RequestMapping("/list")
    public Result list(OrderQuery orderQuery, HttpSession session) {
        User user = (User) session.getAttribute("user");
        orderQuery.setUserId(user.getId());
        List<OrderVO> list = orderService.list(orderQuery);
        return Result.ok(list);
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(Order order, HttpSession session) {
        OrderItem orderItem = (OrderItem) session.getAttribute("orderitem");
        order.setOrderNo(order.getOrderNo());
        orderService.updateStatus(order);
        return Result.ok();
    }

/*        @RequestMapping("/updateByUserId")
    public Result updateByUserId(Cart cart, HttpSession session) {
        User user = (User) session.getAttribute("user");
        cart.setUserId(user.getId());
        cartService.updateByUserId(cart);
        return Result.ok("更新成功");
    }*/
}

